package com.xz.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xz.R;
import com.xz.entity.Member;
import com.xz.entity.Video;
import com.xz.entity.Vplayer;
import com.xz.entity.frontvo.VideoFrontVo;
import com.xz.entity.frontvo.VideoPlayerVo;
import com.xz.entity.vo.MemberQuery;
import com.xz.entity.vo.VideoQuery;
import com.xz.service.VideoService;
import com.xz.service.VplayerService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/video/front")
public class FrontVideoController {
    @Autowired
    private VideoService videoService;
    @Autowired
    private VplayerService vplayerService;
    @GetMapping("getRecommend")
    public R getRecommend() {
        //查新当前热门视频记录
        IPage<Video> pageInfo=videoService.getRecommend();
        long total = pageInfo.getTotal();
        List<Video> list = pageInfo.getRecords(); //数据list集合
        return R.ok().data("total",total).data("list",list);
    }

    /*
     根据条件查询
     */
    @PostMapping("page/{current}/{limit}")
    public R pageCondition(@PathVariable long current, @PathVariable long limit,
                           @RequestBody(required = false)VideoFrontVo videoFrontVo) {
        //存入redis
        IPage<Video> pageInfo=videoService.pageCondition(current,limit,videoFrontVo);
        long total = pageInfo.getTotal();
        List<Video> list = pageInfo.getRecords(); //数据list集合
        return R.ok().data("total",total).data("list",list);
    }

    //播放视频
    @GetMapping("getPlayer/{videoId}")
    public R getPlayer(@PathVariable String videoId){
        VideoPlayerVo videoPlayerVo=vplayerService.getPlayerOne(videoId);
        return R.ok().data("videoPlayerVO",videoPlayerVo);
    }
}
